home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / obsolete / widmain.pro < prev    next >
Text File  |  1997-07-08  |  15KB  |  507 lines

  1. ;
  2. ; $Id: widmain.pro,v 1.14 1997/01/15 03:11:50 ali Exp $
  3. ;
  4. ;  WidMain
  5. ;   Main object class definition.
  6. ;
  7. ; Copyright (c) 1993-1997, Research Systems, Inc.  All rights reserved.
  8. ;   Unauthorized reproduction prohibited.
  9. ;
  10. ; MODIFICATION HISTORY
  11. ;       Written by:     Joshua Goldstein,       12/93
  12. ;
  13. ;
  14.  
  15. ;
  16. ;  UpdateMainDlg
  17. ;       Set controls in top level base to reflect current settings
  18. ;       in the MAIN widget object
  19. ;
  20. PRO UpdateMainDlg
  21.  
  22.   COMMON WidEd_Comm
  23.  
  24.     ;   Now update top dialog box to reflect changes
  25.  
  26.     Ptr2Obj, TopDlg, DialogInfo
  27.     Ptr2Obj, TopPtr, Obj
  28.  
  29.     Foci    = DialogInfo.Foci
  30.  
  31.     WIDGET_CONTROL, Foci[0], SET_VALUE=Obj.Name
  32.     WIDGET_CONTROL, Foci[1], SET_VALUE=Obj.NRowCol
  33.     WIDGET_CONTROL, Foci[2], SET_VALUE=Obj.Space
  34.     WIDGET_CONTROL, Foci[3], SET_VALUE=Obj.XPad
  35.     WIDGET_CONTROL, Foci[4], SET_VALUE=Obj.YPad
  36.     WIDGET_CONTROL, Foci[5], SET_VALUE=Obj.XScrollSize
  37.     WIDGET_CONTROL, Foci[6], SET_VALUE=Obj.YScrollSize
  38.  
  39.     ;   Become a row/col/bbs.  Work around toolkit dependencies
  40.     FOR I=0,2 DO $
  41.         WIDGET_CONTROL, DialogInfo.Btns[I], SET_BUTTON=(Obj.BaseType EQ I)
  42.  
  43.     WIDGET_CONTROL, DialogInfo.RowColId, SENSITIVE=(Obj.BaseType NE 0)
  44.  
  45.     Obj2Ptr, Obj, TopPtr
  46.     Obj2Ptr, DialogInfo, TopDlg
  47. END
  48.  
  49. ;
  50. ;  MAIN_Alloc
  51. ;       Allocate a main object (if Ptr is NULL or just invalid)
  52. ;   There are 3 base object classes (MAIN,DEP, and BASE) so they call
  53. ;   a common routine to allocate base objects.
  54. ;
  55. PRO MAIN_Alloc, Parent, Ptr
  56.   COMMON WidEd_Comm
  57.  
  58.     ; Make a pointer. Maybe.
  59.     IF KEYWORD_SET(Ptr) EQ 0 THEN $
  60.         Ptr = WIDGET_BASE()
  61.     MakeBaseObj, Parent, Obj, "MAIN"                ; Make a base object
  62.     Obj2Ptr, Obj, Ptr                               ; Store object in pointer
  63.  
  64. END
  65.  
  66. ;
  67. ;  MAIN_Destroy
  68. ;   Remove children objects and dependent bases as well.
  69. ;   We don't destroy the main base, just reset all of its fields
  70. ;   to their default state.
  71. ;
  72. PRO MAIN_Destroy, Ptr
  73.  
  74.   COMMON WidEd_Comm
  75.  
  76.     Ptr2Obj, Ptr, Obj
  77.     DoList, Obj.Children, "Destroy"     ; Destroy children
  78.     DoList, Obj.Next, "Destroy"         ; Destroy dependent bases
  79.     IF WIDGET_INFO(Obj.AttrDlg, /VALID) THEN $
  80.         WIDGET_CONTROL, Obj.AttrDlg, /DESTROY
  81.     MakeBaseObj, 0L, CleanObj, "MAIN"       ; Create a virgin MAIN
  82.     Obj2Ptr, CleanObj, Ptr              ; Store into used MAIN pointer
  83.  
  84.     IF WIDGET_INFO(TopDlg, /VALID) EQ 0 THEN BEGIN
  85.         PRint,'Invalid'
  86.         RETURN
  87.     ENDIF
  88.  
  89.     UpdateMainDlg
  90. END
  91.  
  92.  
  93. ;
  94. ;  MAIN_BarEvent
  95. ;   Events from the pull down menu don't have a <STRING> type UVALUE to
  96. ;   use.  Thus we have a separate event routine to handle the menu items.
  97. ;
  98. ;
  99. PRO MAIN_BarEvent, Event
  100.  
  101.   COMMON WidEd_Comm
  102.  
  103.     ;   Too complicated to use the /NO_COPY for this event routine
  104.  
  105.     WIDGET_CONTROL, Event.top, GET_UVALUE=Binfo
  106.  
  107.     Build       = ''
  108.     Do_Generate = 0
  109.  
  110.     CASE Event.Value OF
  111.  
  112.     'File.New':         Dirty, Event.Top, "creating new widget tree", "FileNew"
  113.     'File.Open...':     Dirty, Event.Top, "opening another file", "FileOpen"
  114.  
  115.     'File.Save...':                             FileSave
  116.     'File.Create .PRO.Normal...':               FileGenPro, 1, 0
  117.     'File.Create .PRO.Rewrite Everything...':   FileGenPro, 1, 1
  118.     'File.Create .PRO.Without Header...':       FileGenPro, 0, 0
  119.     'File.Show Object Tree...':                 ShowObjTree, Binfo.ObjPtr
  120.  
  121.     'File.Quit':        BEGIN
  122.         Dirty, Event.Top, "quitting", $
  123.                         "WIDGET_CONTROL,/DESTROY,"+STRTRIM(Event.top)
  124.         RETURN
  125.         END
  126.  
  127.     'Edit.Cut...':              CutChild
  128.     'Edit.Copy...':             CutChild, /COPY
  129.     'Edit.Paste...':            PasteChild
  130.     'Edit.Edit Child...':       EditChild
  131.  
  132.     'Add.Hide Tool Bar':    BEGIN
  133.         WIDGET_CONTROL, Binfo.ToolBar, MAP=0
  134.         WIDGET_CONTROL, Binfo.ToolId, SET_VALUE='Show Tool Bar'
  135.         WIDGET_CONTROL, Binfo.ToolId, SET_UVALUE='Add.Show Tool Bar' ; Hack
  136.         END
  137.     'Add.Show Tool Bar':    BEGIN
  138.         WIDGET_CONTROL, Binfo.ToolBar, MAP=1
  139.         WIDGET_CONTROL, Binfo.ToolId, SET_VALUE='Hide Tool Bar'
  140.         WIDGET_CONTROL, Binfo.ToolId, SET_UVALUE='Add.Hide Tool Bar' ; Hack
  141.         END
  142.  
  143.     'Add.Dependent Base':   BEGIN
  144.  
  145.         ;   the Build facility below only works for adding CHILDREN
  146.         ;   Dependent bases are siblings so we need special code to
  147.         ;   handle that
  148.  
  149.         DEP_Build, Ptr, Base                    ; Allocate base. Make dialog
  150.         SetTag, Ptr, "Next", NextPtr(Binfo.ObjPtr)  ; Add base to TLB list
  151.         SetTag, Binfo.ObjPtr, "Next", Ptr
  152.         UpdateEdit                              ; Update Cut/Paste dialogs
  153.         Do_Generate = 1                         ; Update preview.
  154.         END
  155.  
  156.     'Rebuild':          BEGIN
  157.  
  158.         ;   Hitting the rebuild button causes the interface to
  159.         ;   'Accept' on a newly created widget.  After this, a 'Cancel'
  160.         ;   will not remove the child, instead it will revert it to
  161.         ;   the state it was in when Rebuild was clicked.
  162.  
  163.         N   = N_ELEMENTS(NewDialogs)
  164.         FOR I=1,N-1 DO BEGIN
  165.             IF NewDialogs[I].OldPtr EQ 0L THEN BEGIN        ; Found new widget
  166.  
  167.                 Ptr     = NewDialogs[I].ObjPtr
  168.                 GetType, Ptr, Type
  169.                 ClearVar,Copy
  170.                 CALL_PROCEDURE, Type+'_Copy', Ptr, Copy     ; Copy it
  171.                 NewDialogs[I].OldPtr    = Copy              ; Save copy
  172.             ENDIF
  173.         ENDFOR
  174.  
  175.         Do_Generate = 1
  176.         END
  177.     'Help':    BEGIN
  178.         HelpFile        = "widabout.txt"
  179.         GET_LUN, Unit
  180.         OPENR, Unit, HelpFile, ERROR=OpenError
  181.         IF OpenError NE 0 THEN $
  182.             HelpFile = FilePath("widabout.txt", SUBDIR=["help", "widget"])
  183.         FREE_LUN, Unit
  184.         XDisplayFile, HelpFile, TITLE='About the Widget Builder'
  185.         END
  186.  
  187.     ELSE:   BEGIN
  188.         IF STRMID(Event.Value,0,4) EQ "Add." THEN BEGIN
  189.             Idx     = WHERE(STRMID(Event.Value,4,100) EQ AddList.Menu)
  190.             Build   = AddList[Idx].Class
  191.         ENDIF ELSE MESSAGE, 'Unprocessed event: ' + Event.Value
  192.         END
  193.     ENDCASE
  194.  
  195.     ;   Common functionality for most Add.XXX requests
  196.  
  197.     IF Build NE '' THEN BEGIN
  198.         ;   Allocate object and create a dialog box as well
  199.         Ptr = 0L                ; Make an invalid ptr but not <UNDEFINED>
  200.         CALL_PROCEDURE, Build+'_Build', Ptr, Binfo.ObjPtr
  201.  
  202.         ;   Add child to our child list.  Note that Base object
  203.         ;   do not get added to the active dialog box list
  204.  
  205.         AddChild, Binfo.ObjPtr, Ptr, NO_CANCEL=(Build EQ 'BASE')
  206.     ENDIF
  207.  
  208.     ;   See if we should update the preview
  209.     IF Do_Generate THEN Generate
  210. END
  211.  
  212.  
  213. ;
  214. ;  MAIN_Event
  215. ;   Normal event handling routine for a main object
  216. ;   These affect attributes of the MAIN widget
  217. ;
  218. PRO MAIN_Event, Event
  219.  
  220.   COMMON WidEd_Comm
  221.  
  222.     WIDGET_CONTROL, Event.Id, GET_UVALUE=Ev
  223.     WIDGET_CONTROL, Event.Top, GET_UVALUE=Binfo, /NO_COPY
  224.  
  225.     Ptr2Obj, Binfo.ObjPtr, Obj
  226.  
  227.     CASE Ev OF
  228.     'TITLE':    Obj.Name    = Event.Value
  229.  
  230.     'Bbs':      BEGIN               ; Make base a bulletin board
  231.         Obj.BaseType        = 0
  232.         WIDGET_CONTROL, Binfo.RowColId, SENSITIVE=0
  233.         END
  234.     'Row':                BEGIN
  235.         Obj.BaseType        = 1
  236.         WIDGET_CONTROL, Binfo.RowColId, SENSITIVE=1
  237.         END
  238.     'Column':        BEGIN
  239.         Obj.BaseType        = 2
  240.         WIDGET_CONTROL, Binfo.RowColId, SENSITIVE=1
  241.         END
  242.  
  243.     ;   Characteristic set in main dialog
  244.  
  245.     'NROW':         Obj.NRowCol     = Event.Value
  246.     'SPACE':        Obj.Space       = Event.Value
  247.     'XPAD':         Obj.XPad        = Event.Value
  248.     'YPAD':         Obj.YPad        = Event.Value
  249.     'XSCROLL':      Obj.XScrollSize = Event.Value
  250.     'YSCROLL':      Obj.YScrollSize = Event.Value
  251.  
  252.     ;   User wants to see the 'Additional attributes' dialog
  253.     'ATTR':         MAIN_BuildAttr, Event.Top, Binfo.ObjPtr, Obj
  254.  
  255.     ;   Additional Attribute Events
  256.  
  257.     'XSIZE':        Obj.XSize       = Event.Value
  258.     'YSIZE':        Obj.YSize       = Event.Value
  259.     'XOFFSET':      Obj.XOffset     = Event.Value
  260.     'YOFFSET':      Obj.YOffset     = Event.Value
  261. ;   'EVENT_FUNC':   Obj.EventFunc   = Event.Value
  262.     'EVENT_PROC':   Obj.EventProc   = Event.Value
  263.     'GETFUNC':      Obj.GetFunc     = Event.Value
  264.     'SETPROC':      Obj.SetProc     = Event.Value
  265.     'KILLPROC':     Obj.KillProc    = Event.Value
  266.     'DO_TLB':       Obj.TLBEvents   = 1 - Obj.TLBEvents
  267.     'MAPPED':       Obj.BaseMapped  = 1 - Obj.BaseMapped
  268.     'DONE':         BEGIN
  269.                     Obj2Ptr, Obj, Binfo.ObjPtr
  270.                     WIDGET_CONTROL, Event.Top, SET_UVALUE=Binfo, /NO_COPY
  271.                     WIDGET_CONTROL, Event.Top, /DESTROY
  272.                     RETURN
  273.                     END
  274.     ELSE:           MESSAGE, 'Unprocessed event: ' + Ev
  275.     ENDCASE
  276.  
  277.     Dirty   = 1     ; We've changed something since the last save
  278.  
  279.     SetNextFocus, Binfo, Event      ; Set next keyboard focus as necessary
  280.     Obj2Ptr, Obj, Binfo.ObjPtr      ; Put object back into pointer
  281.     WIDGET_CONTROL, Event.top, SET_UVALUE=Binfo, /NO_COPY
  282. END
  283.  
  284.  
  285. ;
  286. ;  MAIN_Build
  287. ;   Create the top level dialog box.  Create top level object as well
  288. ;   if ptr is nil.
  289. ;
  290. PRO MAIN_Build, Ptr, Base
  291.  
  292.   COMMON WidEd_Comm 
  293.  
  294.     MAIN_Alloc, 0L, Ptr               ; Allocate object if necessary
  295.  
  296.     Ptr2Obj, Ptr, Obj
  297.  
  298.     AddMenu = MakeAddMenu()
  299.  
  300.     ;   Create menu bar
  301.  
  302.     MenuBarDesc = [                             $
  303.         { CW_PDMENU_S, 1, 'File' },             $
  304.           { CW_PDMENU_S, 0, 'New' },            $
  305.           { CW_PDMENU_S, 0, 'Open...' },        $
  306.           { CW_PDMENU_S, 0, 'Save...' },        $
  307.           { CW_PDMENU_S, 1, 'Create .PRO' },    $
  308.             { CW_PDMENU_S, 0, 'Normal...' },    $
  309.             { CW_PDMENU_S, 0, 'Rewrite Everything...' },$
  310.             { CW_PDMENU_S, 2, 'Without Header...' },    $
  311.           { CW_PDMENU_S, 0, 'Show Object Tree...' }, $
  312.           { CW_PDMENU_S, 2, 'Quit' },           $
  313.         { CW_PDMENU_S, 1, 'Edit' },             $
  314.           { CW_PDMENU_S, 0, 'Cut...' },         $
  315.           { CW_PDMENU_S, 0, 'Copy...' },        $
  316.           { CW_PDMENU_S, 0, 'Paste...' },       $
  317.           { CW_PDMENU_S, 2, 'Edit Child...' },  $
  318.         { CW_PDMENU_S, 1, 'Add' },              $
  319.           { CW_PDMENU_S, 0, 'Hide Tool Bar' },  $
  320.           AddMenu,                              $
  321.           { CW_PDMENU_S, 2, 'Dependent Base' }, $
  322.         { CW_PDMENU_S, 0, 'Rebuild' },          $
  323.         { CW_PDMENU_S, 2, 'Help' }              $
  324.     ]
  325.  
  326.     Title       = "Widget Builder"
  327.  
  328.     Base        = WIDGET_BASE(/COLUMN, TITLE=Title)
  329.     MenuBar     = CW_PDMENU(Base, MenuBarDesc, IDS=Ids, /RETURN_FULL_NAME)
  330.  
  331.     ;   Save cut/paste ids.  These change sensitivity to reflect
  332.     ;   changes in cutlist and existence of children.
  333.  
  334.     _CutId      = Ids[11]
  335.     _CopyId     = Ids[12]
  336.     _PasteId    = Ids[13]
  337.     _EditId     = Ids[14]
  338.     ToolId      = Ids[16]
  339.  
  340.     Foci        = LONARR(7)
  341.  
  342.     ;   At this point there are no children to cut/copy or edit
  343.     WIDGET_CONTROL, _CutId, SENSITIVE=0
  344.     WIDGET_CONTROL, _CopyId, SENSITIVE=0
  345.     WIDGET_CONTROL, _EditId, SENSITIVE=0
  346.  
  347.     ;   There could be something to paste if the cutlist is non-nil
  348.     WIDGET_CONTROL, _PasteId, SENSITIVE=(CutList NE 0L)
  349.  
  350.     BuildToolBar, Base, Toolbar         ; There could be a toolbar
  351.  
  352.  
  353.     Base1   = WIDGET_BASE(Base, /COLUMN, EVENT_PRO='MAIN_Event')
  354.     Label   = WIDGET_LABEL(Base1,VALUE='Top Level Base')
  355.  
  356.     Foci[0] = Field(Base1, "Title:", Obj.Name, "TITLE", SIZE=50, /STRING)
  357.     BuildBaseType, Base, Obj, Foci, 1, RowColId, Btns
  358.     BuildXY, Base, Obj, Foci, 1+4, /SIZE
  359.     Dummy   = WIDGET_BUTTON(Base, VALUE='More Attributes', $
  360.                 UVALUE='ATTR', EVENT_PRO='MAIN_Event')
  361.  
  362.     ;   Top level dialog has quite a bit of information associated with it.
  363.  
  364.     DlgInfo = { $
  365.         Foci:       Foci, $
  366.         CutId:      _CutId, $
  367.         CopyId:     _CopyId, $
  368.         PasteId:    _PasteId, $
  369.         EditId:     _EditId, $
  370.         RowColId:   RowColId, $
  371.         ToolBar:    ToolBar, $
  372.         ToolId:     ToolId, $
  373.         Btns:       Btns, $
  374.         ObjPtr:     Ptr $
  375.     }
  376.  
  377.     Obj.Dialog  = Base
  378.  
  379.     WIDGET_CONTROL, Base, SET_UVALUE=DlgInfo, /NO_COPY
  380.     WIDGET_CONTROL, Base, /REALIZE
  381.  
  382.     WIDGET_CONTROL, Btns[1], /SET_BUTTON    ; Start life as a row
  383.     WIDGET_CONTROL, RowColId, SENSITIVE=1
  384.  
  385.     Obj2Ptr, Obj, Ptr
  386. END
  387.  
  388. ;
  389. ;   There is no MAIN_Save (see FileSave)
  390. ;
  391.  
  392.  
  393. ;
  394. ;  MAIN_Restore
  395. ;   Read in an widget tree.  Restores the top base and all of its
  396. ;   children and all dependent bases as well.
  397. ;
  398. PRO MAIN_Restore, Unit, Parent, Ptr
  399.  
  400.     Value   = 0
  401.     READU, Unit, Value      ; Part of file format
  402.     urBASE_Restore, Unit, Parent, Ptr, "MAIN"
  403.  
  404.     ;   Restore Dep Bases
  405.  
  406.     Last    = Ptr
  407.     WHILE 1 DO BEGIN
  408.         Value   = 0
  409.         READU, Unit, Value
  410.         IF Value NE 1 THEN RETURN           ; Exit here
  411.  
  412.         ClearVar, Dep
  413.         DEP_Restore, Unit, 0L, Dep
  414.         SetTag, Last, "Next", Dep
  415.         Last    = Dep
  416.     ENDWHILE
  417. END
  418.  
  419.  
  420. ;
  421. ;   MAIN_BuildAttr
  422. ;
  423. ;   Code for this is so similar to DEP_BuildAttr that I combined them
  424. ;   They differed by 1 line
  425. ;
  426. PRO MAIN_BuildAttr, Leader, Ptr, Obj
  427.     DEP_BuildAttr, Leader, Ptr, Obj
  428. END
  429.  
  430. ;
  431. ;  ShowTree
  432. ;   Write an ASCII description of the current object tree
  433. ;   Indentation indicates parenting.
  434. ;
  435. PRO ShowTree, Unit, Ptr, Level
  436.  
  437.     ; ASCII Assumption: 32b is a space
  438.  
  439.     ;   Indentation shows hierarchy
  440.  
  441.     PRINTF, Unit, STRING(REPLICATE(32b,1 + Level * 3)), $
  442.         VarId(Ptr) + "  ( " + GetId(Ptr) + " )"
  443.  
  444.     ;   look inside objects with children
  445.  
  446.     Ptr2Obj, Ptr, Obj
  447.     IF TAG_NAMES(Obj, /STRUCTURE) EQ 'WE_BASE' THEN BEGIN
  448.         Child       = Obj.Children
  449.         NewLevel    = Level + 1
  450.         WHILE Child NE 0L DO BEGIN
  451.             ShowTree, Unit, Child, NewLevel
  452.             Child   = NextPtr(Child)
  453.         ENDWHILE
  454.     ENDIF
  455.     Obj2Ptr, Obj, Ptr
  456. END
  457.  
  458. ;
  459. ;  ShowObjTree
  460. ;   Create a temp file. Write a description of the object tree
  461. ;   to that file and display that file.
  462. ;
  463. PRO ShowObjTree, Ptr
  464.  
  465.     ;   Try to make a filename that will work on all
  466.     ;   operating systems, including special ones
  467.     ;   which only allow 8 character file names. (MS-DOS)
  468.     ;   and ones which require a '.' in every filename (VMS)
  469.  
  470.     ;   This is the low 5 digits of the system time (to the nearest 1/100th sec)
  471.     ;   Names only collided if:
  472.     ;       They are using the same directory and
  473.     ;       they happen to call ShowObjTree in the same time. (t < 1/100 sec)
  474.  
  475.     Magic       = LONG( (SysTime(1) * 100.0) MOD 100000.0)
  476.  
  477.     FileName    = 'wid'+STRTRIM(Magic, 2)+'.tmp'
  478.     OPENW, Unit, FileName, /GET_LUN
  479.  
  480.     ;   Build file contents
  481.  
  482.     WHILE Ptr NE 0 DO BEGIN
  483.         Showtree, Unit, Ptr, 0
  484.         Next    = NextPtr(Ptr)
  485.         IF Next NE 0L THEN BEGIN
  486.             PRINTF,Unit
  487.             PRINTF,Unit,'---------------'
  488.             PRINTF,Unit
  489.         ENDIF
  490.         Ptr = Next
  491.     ENDWHILE
  492.  
  493.     FLUSH, Unit
  494.     CLOSE, Unit
  495.  
  496.     XDisplayFile, FileName, TITLE='Current Widget Tree'     ; Show it
  497.  
  498.     ;   Reopen the file just to delete it
  499.  
  500.     OPENW, Unit, FileName, /DELETE
  501.     CLOSE, Unit
  502.     FREE_LUN, Unit
  503. END
  504.  
  505. PRO WidMain
  506. END
  507.